<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/commons/global.jsp" %>
<style>
.uploadify-button {
	width: 30px;
}

.uploadify-queue-item {
	background: #fff;
}

.upload-btn {
	background-color: red;
}
</style>
<link rel="stylesheet" href="${path}/static/huploadify/Huploadify.css" />
<script type="text/javascript"
	src="${path}/static/huploadify/jquery.Huploadify.js"></script>
<script type="text/javascript">
    var deployDataGrid;
    $(function() {
        deployDataGrid = $('#deployDataGrid').datagrid({
            url : '${path}/process/listBpmn',
            striped : true,
            rownumbers : true,
            pagination : true,
            singleSelect : true,
            idField : 'id',
            sortName : 'id',
            sortOrder : 'asc',
            pageSize : 20,
            pageList : [ 10, 20, 30, 40, 50, 100, 200, 300, 400, 500 ],
            columns : [ [
                {
                width : '200',
                title : '流程部署ID',
                field : 'deploymentId'
            },
                {
                width : '200',
                title : '流程定义ID',
                field : 'procDefId'
            },
                {
                width : '200',
                title : '名称',
                field : 'name'
            },
                {
                width : '100',
                title : '流程定义KEY',
                field : 'key'
            },
                {
                width : '100',
                title : 'XML文件',
                field : 'resourceName'
                ,formatter : formatXML
            },
                {
                width : '100',
                title : '图片',
                field : 'diagramResourceName',
                formatter:formatImg
            },{
                    width:'100',
                    title:'版本',
                    field:'version'
                }
              
            ]],
          
            toolbar : '#deployToolbar'
        });
    });
    function formatImg(value, row, index) {
        return '<a class="viewBpmnImg" href="${ctxPath}/process/process-definition?processDefinitionId='+row.procDefId+'&resourceType=image" title="查看图片" target="_blank">'+value+'</a> ';
    }
    function formatXML(value, row, index) {
        return '<a class="viewBpmnImg" href="${ctxPath}/process/process-definition?processDefinitionId='+row.procDefId+'&resourceType=xml" title="查看XML" target="_blank">'+value+'</a> ';
    }
    function adddeployFun() {
    	  parent.$.modalDialog({
              title : '添加部署',
              width : 500,
              height :300,
              href : '${path}/jsp/activiti/deploy/deployAdd.jsp',
              buttons : [ {
                  text : '确定',
                  handler : function() {
                	  $.modalDialog.handler.dialog('close');
                	  deployDataGrid.datagrid('reload');
                  }
              } ]
          });
    }

    function updateElementDef() {
        var ids=new Array();
        var rows = deployDataGrid.datagrid('getSelections');
        if(rows.length!=1){
            $.messager.alert('提示','请选择一条记录！')
        }else{
            var dialog=$('<div>').dialog({
                title : '查看流程节点',
                width : '50%',
                height : '50%',
                modal:true,
                onClose : function() {
                    $(this).dialog('destroy');
                },
                href : '${path}/element/toUpdateElementDef/'+rows[0].procDefId,
                buttons : [ {
                    text : '关闭',
                    handler : function() {
                        dialog.dialog('close');
                    }
                }]
            })
        }
    }
    function setWorkflowFun(){
    	var ids=new Array();
        var rows = deployDataGrid.datagrid('getSelections');
        if(rows.length!=1){
        	$.messager.alert('提示','请选择一条记录！')
        }else{
        	var title='设置【'+rows[0].name+'】流程配置';
        	 parent.$.modalDialog({
                 title : title,
                 width : '80%',
                 height :'80%',
                 href : '${path}/process/initworkflow?processDefinitionId='+rows[0].procDefId,
                 buttons : [ {
                     text : '确定',
                     handler : function() {
                    	 saveTaskNodeInfo();
	                   	 $.modalDialog.handler.dialog('close');
	                   	 deployDataGrid.datagrid('reload');
                     }
                 } ]
             });
        }
    	 
    }
 

    function deletedeployFun() {
    	var ids=new Array();
        var rows = deployDataGrid.datagrid('getSelections');
        if(rows.length>0){
        	for(var i=0;i<rows.length;i++){
        		ids.push(rows[i].deploymentId);
        	}
        	parent.$.messager.confirm('询问', '您是否要删除吗？', function(b) {
                if (b) {
                    progressLoad();
                    $.post('${path}/process/deploy/delete', {"ids":ids.join(",")}
                    , function(result) {
                        if (result.success) {
                            parent.$.messager.alert('提示', result.msg, 'info');
                            deployDataGrid.datagrid('reload');
                        }
                        progressClose();
                    }, 'JSON');
                }
            });
        }else{
        	$.messager.alert('提示','请选择要删除的记录！');
        }
    }
     
  function searchDeploymentFun() {
      deployDataGrid.datagrid('load', $.serializeObject($('#searchDeployment')));
  }

  function cleanDeploymentFun() {
      $('#searchDeployment')[0].reset();
      deployDataGrid.datagrid('load', {});
  }
</script>
<div class="easyui-layout" data-options="fit:true,border:false">
    <div data-options="region:'center',border:true">
        <table id="deployDataGrid" data-options="fit:true,border:false"></table>
    </div>
</div>
<div id="deployToolbar" style="display: none;">
    <form id="searchDeployment">
    <table>
        <tr>
            <td>名称</td>
            <td><input type="text" name="name" class="easyui-text"/>
                <a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'fi-magnifying-glass',plain:true" onclick="searchDeploymentFun();">查询</a>
                <a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'fi-x-circle',plain:true" onclick="cleanDeploymentFun();">清空</a>
            </td>
        </tr>
    </table>
    </form>
    <a onclick="adddeployFun();" href="javascript:void(0);" class="easyui-linkbutton" data-options="plain:true,iconCls:'fi-plus icon-blue'">添加部署</a>
    <a onclick="deletedeployFun();" href="javascript:void(0);" class="easyui-linkbutton" data-options="plain:true,iconCls:'fi-minus icon-blue'">刪除部署</a>
    <a onclick="setWorkflowFun();" href="javascript:void(0);" class="easyui-linkbutton" data-options="plain:true,iconCls:'fi-widget icon-blue'">设置流程</a>
    <a onclick="updateElementDef();" href="javascript:void(0);" class="easyui-linkbutton" data-options="plain:true,iconCls:'fi-eye icon-blue'">查看流程节点</a>
</div>
